package com.ht.dao;

import com.ht.bean.*;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

//系统设置
public interface StytingDao {
    //----------------------------------------------------------------------------------
    //届别设置
    //届别查询:studentfall
    @Select({"<script>",
            "select * from studentfall ",
            "<where>",
            "<if test=\" studentfall.fallId!= null and studentfall.fallId!= ''\">",
            "and fallId=#{studentfall.fallId}",
            "</if>",
            "<if test=\" studentfall.level!= null and studentfall.level!= ''\">",
            "and level like concat('%',#{studentfall.level},'%')",
            "</if>",
            "</where>",
            "<if test=\" lime != null and lime!=''\">",
            "ORDER BY level desc limit #{pid},#{lime}",
            "</if>",
            "</script>"})
    List<Studentfall> litfall(@Param("pid") Integer pid, @Param("lime") Integer lime, @Param("studentfall") Studentfall studentfall);

    //届别表数据的总条数
    @Select({"<script>",
            "select count(*) from studentfall ",
            "<where>",
            "<if test=\" studentfall.fallId!= null and studentfall.fallId!= ''\">",
            "and fallId=#{studentfall.fallId}",
            "</if>",
            "<if test=\" studentfall.level!= null and studentfall.level!= ''\">",
            "and level like concat('%',#{studentfall.level},'%')",
            "</if>",
            "</where>",
            "</script>"})
    int litafall(@Param("studentfall") Studentfall studentfall);

    //新增届别
    @Insert("insert into studentfall values(null,#{studentfall.level},#{studentfall.remark})")
    boolean addfall(@Param("studentfall") Studentfall studentfall);

    //删除届别表的数据
    @Delete("delete from studentfall where fallId=#{fallId}")
    boolean delfall(@Param("fallId") Integer fallId);

    //修改前的查询
    @Select("select * from studentfall where fallId=#{fallId}")
    Studentfall slitfall(@Param("fallId") Integer fallId);

    //修改届别表的数据
    @Update("update studentfall set level=#{studentfall.level},remark=#{studentfall.remark} where fallId=#{studentfall.fallId}")
    boolean updfall(@Param("studentfall") Studentfall studentfall);

    //----------------------------------------------------------------------------------
    //班级类别查询
    @Select({"<script>",
            "select * from classtype ",
            "<where>",
            "<if test=\" classtype.calssTypeId!= null and classtype.calssTypeId!= ''\">",
            "and calssTypeId=#{classtype.calssTypeId}",
            "</if>",
            "<if test=\" classtype.classTypeName!= null and classtype.classTypeName!= ''\">",
            "and classTypeName like concat('%',#{classtype.classTypeName},'%')",
            "</if>",
            "</where>",
            "<if test=\" lime != null and lime!=''\">",
            "ORDER BY calssTypeId desc limit #{pid},#{lime}",
            "</if>",
            "</script>"})
    List<Classtype> litclass(@Param("pid") Integer pid, @Param("lime") Integer lime, @Param("classtype") Classtype classtype);

    //班级类别查询数据条数
    @Select({"<script>",
            "select count(*) from classtype ",
            "<where>",
            "<if test=\" classtype.calssTypeId!= null and classtype.calssTypeId!= ''\">",
            "and calssTypeId=#{classtype.calssTypeId}",
            "</if>",
            "<if test=\" classtype.classTypeName!= null and classtype.classTypeName!= ''\">",
            "and classTypeName like concat('%',#{classtype.classTypeName},'%')",
            "</if>",
            "</where>",
            "</script>"})
    int litclasss(@Param("classtype") Classtype classtype);

    //新增班级类别
    @Insert("insert into classtype values(null,#{classtype.classTypeName})")
    boolean addclass(@Param("classtype") Classtype classtype);

    //删除班级类别表的数据
    @Delete("delete from classtype where calssTypeId=#{calssTypeId}")
    boolean delclass(@Param("calssTypeId") Integer calssTypeId);

    //修改班级类别前的查询
    @Select("select * from classtype where calssTypeId=#{calssTypeId}")
    Classtype slitclass(@Param("calssTypeId") Integer calssTypeId);

    //修改班级类别表的数据
    @Update("update classtype set classTypeName=#{classtype.classTypeName} where calssTypeId=#{classtype.calssTypeId}")
    boolean updeclass(@Param("classtype") Classtype classtype);

    //----------------------------------------------------------------------------------
    //部门类查询
    @Select("select * from dep ")
    List<Dep> litdepp();

    //部门类别查询
    @Select({"<script>",
            "select d.depid,d.depName,e.empName,p.depName deepName,d.personnel from dep d,emp e,dep p",
            "<where>",
            "and d.parentId = p.depid and d.chairman = e.empId",
            "<if test=\" dep.depid!= null and dep.depid!= ''\">",
            "and d.depid=#{dep.depid}",
            "</if>",
            "<if test=\" dep.depName!= null and dep.depName!= ''\">",
            "and d.depName like concat('%',#{dep.depName},'%')",
            "</if>",
            "<if test=\" dep.parentId!= null and dep.parentId!= ''\">",
            "and d.parentId=#{dep.parentId}",
            "</if>",
            "<if test=\" dep.chairman!= null and dep.chairman!= ''\">",
            "and d.chairman=#{dep.chairman}",
            "</if>",
            "<if test=\" dep.personnel!= null and dep.personnel!= ''\">",
            "and d.personnel=#{dep.personnel}",
            "</if>",
            "</where>",
            "<if test=\" lime != null and lime!=''\">",
            "limit #{pid},#{lime}",
            "</if>",
            "</script>"})
    List<Map> litdep(@Param("pid") Integer pid, @Param("lime") Integer lime, @Param("dep") Dep dep);

    //部门类别查询数据条数
    @Select({"<script>",
            "select count(*) from dep d,emp e,dep p",
            "<where>",
            "and d.parentId = p.depid and d.chairman = e.empId",
            "<if test=\" dep.depid!= null and dep.depid!= ''\">",
            "and d.depid=#{dep.depid}",
            "</if>",
            "<if test=\" dep.depName!= null and dep.depName!= ''\">",
            "and d.depName like concat('%',#{dep.depName},'%')",
            "</if>",
            "<if test=\" dep.parentId!= null and dep.parentId!= ''\">",
            "and d.parentId=#{dep.parentId}",
            "</if>",
            "<if test=\" dep.chairman!= null and dep.chairman!= ''\">",
            "and d.chairman=#{dep.chairman}",
            "</if>",
            "<if test=\" dep.personnel!= null and dep.personnel!= ''\">",
            "and d.personnel=#{dep.personnel}",
            "</if>",
            "</where>",
            "</script>"})
    int littdep(@Param("dep") Dep dep);

    //新增部门类别
    @Insert("insert into dep values(null,#{dep.depName},#{dep.parentId},#{dep.chairman},#{dep.remark},#{dep.personnel})")
    boolean adddep(@Param("dep") Dep dep);

    //删除部门类别表的数据
    @Delete("delete from dep where depid=#{depid}")
    boolean deldep(@Param("depid") Integer depid);

    //修改部门类别前的查询
    @Select("select * from dep where depid=#{depid}")
    Dep slittdep(@Param("depid") Integer depid);

    //修改部门类别表的数据
    @Update("update dep set depName=#{dep.depName} , parentId=#{dep.parentId} , chairman=#{dep.chairman} , remark=#{dep.remark} , personnel=#{dep.personnel} where depid=#{dep.depid}")
    boolean updfdep(@Param("dep") Dep dep);

    //---------------------------------------------------------------------------------------------------------
    //院系管理
    //院系表查询
    @Select({"<script>",
            "select * from dept ",
            "<where>",
            "<if test=\" dept.deptId!= null and dept.deptId!= ''\">",
            "and deptId=#{dept.deptId}",
            "</if>",
            "<if test=\" dept.deptName!= null and dept.deptName!= ''\">",
            "and deptName like concat('%',#{dept.deptName},'%')",
            "</if>",
            "<if test=\" dept.remark!= null and dept.remark!= ''\">",
            "and remark like concat('%',#{dept.remark},'%')",
            "</if>",
            "</where>",
            "<if test=\" lime != null and lime!='' and lime !=  0\">",
            "limit #{pid},#{lime}",
            "</if>",
            "</script>"})
    List<Dept> litdept(@Param("pid") Integer pid, @Param("lime") Integer lime, @Param("dept") Dept dept);

    //院系表查询数据条数
    @Select({"<script>",
            "select count(*) from dept ",
            "<where>",
            "<if test=\" dept.deptId!= null and dept.deptId!= ''\">",
            "and deptId=#{dept.deptId}",
            "</if>",
            "<if test=\" dept.deptName!= null and dept.deptName!= ''\">",
            "and deptName like concat('%',#{dept.deptName},'%')",
            "</if>",
            "<if test=\" dept.remark!= null and dept.remark!= ''\">",
            "and remark like concat('%',#{dept.remark},'%')",
            "</if>",
            "</where>",
            "</script>"})
    int litdeptt(@Param("dept") Dept dept);

    //新增院系表
    @Insert("insert into dept values(null,#{dept.deptName},#{dept.remark})")
    boolean adddept(@Param("dept") Dept dept);

    //删除院系表的数据
    @Delete("delete from dept where deptId=#{deptId}")
    boolean deldept(@Param("deptId") Integer deptId);

    //修改院系表前的查询
    @Select("select * from dept where deptId=#{deptId}")
    Dept slitdept(@Param("deptId") Integer deptId);

    //修改院系表的数据
    @Update("update dept set deptName=#{dept.deptName} ,remark=#{dept.remark} where deptId=#{dept.deptId}")
    boolean updedept(@Param("dept") Dept dept);


    //-------------------------------------------------------------------------------------------------------------------------------------------
    //专业管理
    //院系表的查询
    @Select("select dept.deptId,dept.deptName from dept ")
    List<Map> majdept();

    //专业表查询
    @Select({"<script>",
            "select m.majorId,m.majorName,m.remark,d.deptName from major m,dept d",
            "<where>",
            "and m.deptId = d.deptId",
            "<if test=\" major.majorId!= null and major.majorId!= ''\">",
            "and m.majorId=#{major.majorId}",
            "</if>",
            "<if test=\" major.majorName!= null and major.majorName!= ''\">",
            "and m.majorName like concat('%',#{major.majorName},'%')",
            "</if>",
            "<if test=\" major.deptId!= null and major.deptId!= ''\">",
            "and m.deptId = #{major.deptId}",
            "</if>",
            "<if test=\" major.remark!= null and major.remark!= ''\">",
            "and m.remark like concat('%',#{major.remark},'%')",
            "</if>",
            "</where>",
            "<if test=\" lime != null and lime!=''\">",
            "limit #{pid},#{lime}",
            "</if>",
            "</script>"})
    List<Map> litmajor(@Param("pid") Integer pid, @Param("lime") Integer lime, @Param("major") Major major);

    //专业表查询数据条数
    @Select({"<script>",
            "select count(*) from major m,dept d ",
            "<where>",
            "and m.deptId = d.deptId",
            "<if test=\" major.majorId!= null and major.majorId!= ''\">",
            "and m.majorId=#{major.majorId}",
            "</if>",
            "<if test=\" major.majorName!= null and major.majorName!= ''\">",
            "and m.majorName like concat('%',#{major.majorName},'%')",
            "</if>",
            "<if test=\" major.deptId!= null and major.deptId!= ''\">",
            "and m.deptId like concat('%',#{major.deptId},'%')",
            "</if>",
            "<if test=\" major.remark!= null and major.remark!= ''\">",
            "and m.remark like concat('%',#{major.remark},'%')",
            "</if>",
            "</where>",
            "</script>"})
    int litmajorr(@Param("major") Major major);

    //新增院专业表
    @Insert("insert into major values(null,#{major.majorName} , #{major.deptId} ,#{major.remark})")
    boolean adddmajor(@Param("major") Major major);

    //删除专业表的数据
    @Delete("delete from major where majorId=#{majorId}")
    boolean delmajor(@Param("majorId") Integer majorId);

    //修改专业表前的查询
    @Select("select * from major where majorId=#{majorId}")
    Major slitmajort(@Param("majorId") Integer majorId);

    //修改专业表的数据
    @Update("update major set majorName=#{major.majorName} ,deptId=#{major.deptId} ,remark=#{major.remark} where majorId=#{major.majorId}")
    boolean updemajor(@Param("major") Major major);

    //---------------------------------------------------------------------------------------------------------
    //答辩管理
    //答辩表查询
    @Select({"<script>",
            "select * from project",
            "<where>",
            "<if test=\" project.projectId!= null and project.projectId!= ''\">",
            "and projectId=#{project.projectId}",
            "</if>",
            "<if test=\" project.projectName!= null and project.projectName!= ''\">",
            "and projectName like concat('%',#{project.projectName},'%')",
            "</if>",
            "<if test=\" project.remark!= null and project.remark!= ''\">",
            "and remark like concat('%',#{project.remark},'%')",
            "</if>",
            "</where>",
            "<if test=\" lime != null and lime!=''\">",
            "limit #{pid},#{lime}",
            "</if>",
            "</script>"})
    List<Project> litproject(@Param("pid") Integer pid, @Param("lime") Integer lime, @Param("project") Project project);

    //答辩表查询数据条数
    @Select({"<script>",
            "select count(*) from project ",
            "<where>",
            "<if test=\" project.projectId!= null and project.projectId!= ''\">",
            "and projectId=#{project.projectId}",
            "</if>",
            "<if test=\" project.projectName!= null and project.projectName!= ''\">",
            "and projectName like concat('%',#{project.projectName},'%')",
            "</if>",
            "<if test=\" project.remark!= null and project.remark!= ''\">",
            "and remark like concat('%',#{project.remark},'%')",
            "</if>",
            "</where>",
            "</script>"})
    int litprojectt(@Param("project") Project project);

    //新增答辩表
    @Insert("insert into project values(null,#{project.projectName} , #{project.remark})")
    boolean adddproject(@Param("project") Project project);

    //删除答辩表的数据
    @Delete("delete from project where projectId=#{projectId}")
    boolean delproject(@Param("projectId") Integer projectId);

    //修改答辩表前的查询
    @Select("select * from project where projectId=#{projectId}")
    Project slitproject(@Param("projectId") Integer projectId);

    //修改答辩表的数据
    @Update("update project set projectName=#{project.projectName} ,remark=#{project.remark} where projectId=#{project.projectId}")
    boolean updeproject(@Param("project") Project project);

    //------------------------------------------------------------------------------------------------------------
    //权限查询
    @Select("select  mdu.controller from charmodule chm,module mdu,characters cha,charemp cem where chm.moduleId= mdu.moduleId  and chm.characterId = cha.characterId and cha.characterId = cem.characterId  and cem.empId = #{empId}")
    List<Module> inquire (@Param("empId") Integer empId);
}
